<?php

require "./lib/src/skey.php";

$images_url = base_url('images');
$upload_url = base_url('uploads');
$admin_url = base_url('otakkanan');
$kirim_url = base_url('otakkiri');


$menu = $this->uri->segment(3, "all");
$mapdir = "	<a href='$admin_url/' class='taut'>Home</a> &gt; ";
$perusahaan = $this->adminmodel->get_usaha($uid);
$daftarusaha = "";

switch($menu)
{
	case "baru":
	
		if($perusahaan !== FALSE)
		{
			$daftarusaha = "<select name='perusahaan'>";
			foreach($perusahaan AS $usaha)
			{
				$daftarusaha .= "<option value='$usaha->idperusahaan'>$usaha->nama</option>";
			}
			$daftarusaha .= "</select>";
		}
		else
		{
			pesan('Untuk Menambah Lowongan Pekerjaan anda harus memiliki perusahaan!\nTambah dulu perusahaan.',base_url('otakkanan/perusahaan/baru'));
			exit(0);
		}
		
		$mapdir .= "
			<a href='$admin_url/loker' class='taut'>Lowongan Kerja</a>
			&gt; 
			<b>Lowongan Baru</b>
		";
		
		
		$isipage = "
				<div id='content2'>
						<h3>Tambah Lowongan Kerja</h3>
							
							<div class='isicontent2'>
								  <br />
								  <p>
									<b>Perhatian!</b> setiap informasi yang anda kirim (publish) merupakan tanggung jawab ANDA SEPENUHNYA. 
								  </p>
								  <br />
							</div>
							<div class='clear'></div>
							
							<div class='isicontent2'>
							
							  <form id='FrmMasukan' action='$kirim_url/tambahloker' method='post' onsubmit='return validasi_loker(this)'  enctype='multipart/form-data'  >
								
									<table>
										<tbody>
											<tr>
												<td class='left'>Posisi Kebutuhan*  </td>
												<td class='right'><input name='posisi' type='text' placeholder='Posisi Lowongan' /></td>
											</tr>
											<tr>
												<td class='left'>Perusahaan *  </td>
												<td class='right'>$daftarusaha</td>
											</tr>
											<tr>
												<td class='left'>Deskripsi *  </td>
												<td class='right'><textarea name='deskripsi' id='deskripsi' placeholder='Deskripsi kebutuhan' cols='30' rows='5'>Deskripsi Kebutuhan</textarea></td>
											</tr>
											<tr>
												<td class='left'>Tipe *  </td>
												<td class='right'>
													<select name='tipe'>
														<option value='ft'>Full Time</option>
														<option value='pt'>Part Time</option>
														<option value='fl'>Freelance</option>
													</select>
												</td>
											</tr>
											<tr>
												<td class='left'>Lokasi *  </td>
												<td class='right'><input type='text' name='lokasi' placeholder='Lokasi Penempatan' />
												</td>
											</tr>
											<tr>
												<td class='left'>Cara Melamar * </td>
												<td class='right'><textarea name='cara' id='deskripsi2' placeholder='Cara Melamar' cols='30' rows='5'></textarea></td>
											</tr>
											<tr>
												<td class='left'>Deadline * </td>
												<td class='right'><input type='text' name='berakhir' id='berakhir' />
													<div class='note'>format : yyyy-mm-dd</div>
												</td>
											</tr>
											
											<tr>
												<td class='left'>Gambar  </td>
												<td class='right'><input name='gambar' type='file' />
												<br /><div class='keterangan'>Anda juga dapat menambahkan gambar dan kurang dari 1 MB.</div></td>
											</tr>
											
											<tr>
												<td class='left'>&nbsp;</td>
												<td class='right'>Tanda Bintang (*) berarti Kolom wajib Diisi</td>
											</tr>
											<tr>
												<td class='left'> &nbsp; </td>
												<td class='right'><input type='submit' value='Tambah'> &nbsp; <input type='reset' value='Ulang'></td>
											</tr>
										
										</tbody>
									</table>
									
							  </form>
							</div>
							
						</div>
			";
		
	;
	break;
	
	case "edit":
	
		$mapdir .= "
			<a href='$admin_url/loker' class='taut'>Lowongan Kerja</a>
			&gt; 
			<b>Edit Lowongan</b>
		";
		
		$idl = $this->input->get('idl');
		$hasil = $this->adminmodel->get_data_loker($idl);
		
		if($hasil !== FALSE)
		{
			foreach($hasil AS $hasil2)
			{
				$daftarusaha = "<select name='perusahaan'>";
				foreach($perusahaan AS $usaha)
				{
					if($usaha->idperusahaan !== $hasil2->idperusahaan)
					{
						$daftarusaha .= "<option value='$usaha->idperusahaan'>$usaha->nama</option>";
					}
					else
					{
						$daftarusaha .= "<option value='$usaha->idperusahaan' selected='selected'>$usaha->nama</option>";
					}
				}
				$daftarusaha .= "</select>";
				
				
				$posisi = html_escape($hasil2->posisi);
				$lokasi = html_escape($hasil2->lokasi);
				
				$tampil = "
							<tr>
								<td class='left'>Posisi Kebutuhan *  </td>
								<td class='right'><input name='posisi' type='text' value='$posisi' /></td>
							</tr>
							<tr>
								<td class='left'>Perusahaan *  </td>
								<td class='right'>$daftarusaha</td>
							</tr>
							<tr>
								<td class='left'>Deskripsi *  </td>
								<td class='right'><textarea name='deskripsi' id='deskripsi' cols='30' rows='5'>$hasil2->deskripsi</textarea></td>
							</tr>
							<tr>
								<td class='left'>Tipe *  </td>
								<td class='right'>
									<select name='tipe'>
										<option value='ft'>Full Time</option>
										<option value='pt'>Part Time</option>
										<option value='fl'>Freelance</option>
									</select>
								</td>
							</tr>
							<tr>
								<td class='left'>Lokasi *  </td>
								<td class='right'><input type='text' name='lokasi' value='$lokasi' />
								</td>
							</tr>
							<tr>
								<td class='left'>Cara Melamar *  </td>
								<td class='right'><textarea name='cara' placeholder='Cara Melamar' id='deskripsi2' cols='30' rows='5'>$hasil2->cara</textarea></td>
							</tr>
							<tr>
								<td class='left'>Berakhir *  </td>
								<td class='right'><input type='text' name='berakhir' id='berakhir' value='$hasil2->berakhir' />
									<div class='note'>format : yyyy-mm-dd</div>
								</td>
							</tr>
							
							<tr>
								<td class='left'>Gambar  </td>
								<td class='right'><input name='gambar' type='file' />
								<br /><div class='keterangan'>Anda juga dapat menambahkan/mengubah gambar.</div></td>
							</tr>
							<tr>
								<td class='left'>&nbsp;</td>
								<td class='right'>NB : Tanda Bintang (*) berarti Kolom wajib Diisi</td>
							</tr>
							<tr>
								<td class='left'> &nbsp; </td>
								<td class='right'>
								<input type='hidden' name='oldgambar' value='$hasil2->gambar' />
								<input type='hidden' name='idl' value='$idl' /><input type='submit' value='Ubah'> &nbsp; <input type='reset' value='Ulang'></td>
							</tr>";
			}
		}else{
			$tampil = "<tr>
							<td class='left'>&nbsp;</td>
							<td class='right'>Data Tidak Ditemukan</td>
						</tr>";
		}
		
		$isipage = "
				<div id='content2'>
					<h3>Edit Lowongan</h3>
						<div class='isicontent2'>
						
						  <form id='FrmMasukan' action='$kirim_url/updateloker' method='post' enctype='multipart/form-data' >
							
								<table>
									<tbody>
									
										$tampil
									
									</tbody>
								</table>
								
						  </form>
						</div>
						
					</div>
			";
	;
	break;
	
	
	case "detail":
		$mapdir .= "
			<a href='$admin_url/loker' class='taut'>Lowongan Kerja</a>
			&gt; 
			<b>Detail</b>
		";
		
		$idl = $this->input->get('idl');
		$hasil = $this->adminmodel->get_data_loker($idl);
		
		if($hasil !== FALSE)
		{
			foreach($hasil AS $hasil2)
			{
				
				$posisi = html_escape($hasil2->posisi);
				$deskripsi = auto_link(xss_clean($hasil2->deskripsi));
				$caralamar = auto_link(xss_clean($hasil2->cara));
				$lokasi = html_escape($hasil2->lokasi);
				
				if($hasil2->tipe == "ft"){
					$tipe = "Full Time";
				}else if($hasil2->tipe == "pt"){
					$tipe = "Part Time";
				}else{
					$tipe = "Freelance";
				}
				
				if($hasil2->gambar != ""){
					$gambar = "<a id='lihat' href='$upload_url/lowongan/$hasil2->gambar'><img alt='Gambar Produk' src='$upload_url/lowongan/$hasil2->gambar' class='preview' /></a>";
				}else{
					$gambar = "";
				}
				
				
				$berakhir = date("d F Y", strtotime($hasil2->berakhir));
				$hariini = date("Y-m-d");
				$status = "";
				
				if($hasil2->berakhir < $hariini)
				{
					$status = "(telah berkahir)";
				}
				
				$tampil = "<tr>
								<td class='left'>Posisi  </td>
								<td class='right'>
									$posisi 
									<a href='$kirim_url/hapusloker?idl=$idl' onclick='return konfirmhapus()' title='Hapus data lowongan'>Hapus</a>
								</td>
							</tr>
							<tr>
								<td class='left'>Deskripsi Pekerjaan </td>
								<td class='right'>$deskripsi</td>
							</tr>
							<tr>
								<td class='left'>Tipe Pekerjaan </td>
								<td class='right'><b>$tipe</b></td>
							</tr>
							<tr>
								<td class='left'>Lokasi Penempatan</td>
								<td class='right'>$lokasi</td>
							</tr>
							<tr>
								<td class='left'>Cara Melamar </td>
								<td class='right'>$caralamar</td>
							</tr>
							<tr>
								<td class='left'>Berakhir </td>
								<td class='right'>$berakhir $status</td>
							</tr>
							<tr>
								<td class='left'>Gambar/Brosur  </td>
								<td class='right'>$gambar</td>
							</tr>
							
							<tr>
								<td class='left'>&nbsp;</td>
								<td class='right'>&nbsp;</td>
							</tr>
							<tr>
								<td class='left'> &nbsp; </td>
								<td class='right'><a href='$admin_url/loker' class='taut'>&lt;&lt; Kembali</a></td>
							</tr>";
			}
		}else{
			$tampil = "<tr>
							<td class='left'>&nbsp;</td>
							<td class='right'>Data Tidak Ditemukan</td>
						</tr>";
		}
		
		$isipage = "
				<div id='content2'>
						<h3>Detail Loker</h3>
							<div class='isicontent2'>
							
								<table>
									<tbody>
									
										$tampil
									
									</tbody>
								</table>
									
							</div>
							
						</div>
			";
	;
	break;
	
	default:
	
		$mapdir .= "
			<b>Lowongan Kerja</b>
		";
		
		$awal = $this->input->get("awal");
		$loker = $this->adminmodel->get_loker($awal);
		$dataloker = "";
		
		if($loker !== FALSE)
		{
			foreach($loker AS $ldata)
			{
				$idl = $ldata->idjob;
				$posisi = $ldata->posisi;
				
				$berakhir = "";
				$edithapus = "";
				$hariini = date("Y-m-d");
				
				if($ldata->berakhir < $hariini)
				{
					$berakhir = "(<b>Telah berakhir</b>)";
				}
				
				if($ldata->uid == $uid)
				{
					$edithapus = "<a href='$admin_url/loker/edit?idl=$idl' class='taut'>Edit</a> &nbsp; 
						<a href='$kirim_url/hapusloker?idl=$idl' onclick='return konfirmhapus()' title='Hapus data lowongan'>Hapus</a>";
				}
				
				$dataloker .= "
					<tr>
					<td class='left'> $posisi $berakhir </td>
					<td class='right'> 
						<a href='$admin_url/loker/detail?idl=$idl'>Detail</a> &nbsp; 
						$edithapus 
						
					</td>
					</tr>";
			}
			
		}else{
			$dataloker .= "
				<tr>
				<td class='left'>&nbsp;</td>
				<td class='right'>Belum ada data Lowongan. <a href='$admin_url/loker/baru' class='taut'>Tambah Baru?</a>
				</td>
				</tr>";
		}
		
		$config['base_url'] = $admin_url.'/loker?usaha=maju';
		$config['total_rows'] = $this->adminmodel->hitung_data('idjob','dn_job');
		$config['per_page'] = 10; 
		$config['page_query_string'] = TRUE;
		$config['query_string_segment'] = 'awal';

		$this->pagination->initialize($config); 
		$halaman = $this->pagination->create_links();
		
		$isipage = "
				<div id='content2'>
						<h3>Daftar Lowongan Kerja</h3>
							<div class='isicontent2'>
							 <table>
								<tbody>
									<tr><td class='left'><a href='$admin_url/loker/baru' class='taut'>Tambah Baru</a></td><td class='right'>&nbsp;</td></tr>
									<tr><td class='left'>&nbsp;</td><td class='right'>&nbsp;</td></tr>
									$dataloker
									<tr><td class='left'>&nbsp;</td><td class='right'>&nbsp;</td></tr>
									<tr><td class='left'><a href='$admin_url/loker/baru' class='taut'>Tambah Baru</a></td><td class='right'>$halaman</td></tr>
								</tbody>
							 </table>
							</div>
							
					</div>
			";
	;
	break;
}


$data['map_dir'] = $mapdir;
$data['isi_page'] = $isipage;
$data['site_title'] = 'Lowongan Kerja - Dadan Network';
$data['base_url'] = base_url();
$data['tahun_sekarang'] = date("Y");

$this->parser->parse('template/admin', $data);


/* End of file loker.php */
/* Location: ./application/views/admin/loker.php */
